package com.xiaoxu.controller;


import com.xiaoxu.damain.UserData;
import com.xiaoxu.service.Meberrequstservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@RestController
@RequestMapping("/meberrequst")
@CrossOrigin
public class MeberrequstController {

    @Autowired
    private Meberrequstservice meberrequstservice;

    @PostMapping
    public boolean MeberRequst(@RequestBody UserData username){
        SimpleDateFormat df = new SimpleDateFormat("yyyy");
       Date userdate = meberrequstservice.meberrequst(username.getUser_name());
       LocalDateTime todayDate = LocalDateTime.now();
       String todayDateString = todayDate.format(DateTimeFormatter.ofPattern("yyyy"));
       try{
           long createlong = userdate.getTime();
           Date todayDate2 = df.parse(todayDateString);
           long today = todayDate2.getTime();
//           System.out.println(createlong+"createlong");
//           System.out.println(today+"today");
//           System.out.println((today - createlong)/1000000);
           if((((today - createlong)/1000000) > 31536)){
               meberrequstservice.insertMeber(username.getUser_name());
               return true;
           }else {
               return false;
           }
       }catch (Exception e) {
           return false;
       }
    }

}
